package com.zj.study.sync;

import java.util.Objects;
import java.util.Optional;

public enum RefundTradeStateEnum {
  /**
   * ACCEPT：已接收
   * PRE_PAYMENT：预付款已完成
   * FAIL：失败
   * REFUNDED_SUCCESS：退款成功
   */
  ACCEPT,
  PRE_PAYMENT,
  FAIL,
  REFUNDED_SUCCESS,
  ;
  private static final String ACCEPT_VALUE = "A";
  private static final String PRE_PAYMENT_VALUE = "P";
  private static final String FAIL_VALUE = "F";
  private static final String REFUNDED_SUCCESS_VALUE = "S";

  public static Optional<RefundTradeStateEnum> matchEnum(String value) {
    if (Objects.isNull(value)) {
      return Optional.empty();
    }

    switch (value) {
      case ACCEPT_VALUE:
        return Optional.of(ACCEPT);
      case PRE_PAYMENT_VALUE:
        return Optional.of(PRE_PAYMENT);
      case FAIL_VALUE:
        return Optional.of(FAIL);
      case REFUNDED_SUCCESS_VALUE:
        return Optional.of(REFUNDED_SUCCESS);
      default:
        return Optional.empty();
    }
  }

}